/*
 * Copyright 2012 NJUT  qixiaobo. All rights reserved.
 */
package com.fujitsu.nanjing.mobile.base;

import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;

/**
 * BaseService.java
 * <p>
 * T表示原来的domain，U表示对应的example，即数据库相关查询等操作
 * </p>
 * 
 * @author qixb.fnst
 */

public abstract class BaseService<T, U> {
	public abstract T findById(String id);
	public abstract T insert(T t);
	public abstract void update(T t);
	public abstract void delete(T t);
	/**
	 * 当用户没有登录时返回空
	 **/
	public UserDetails getUserDetails() {
		UserDetails user = null;
		if (SecurityContextHolder.getContext().getAuthentication()
				.getPrincipal() instanceof UserDetails) {
			user = (UserDetails) SecurityContextHolder.getContext()
					.getAuthentication().getPrincipal();
		}
		return user;
	}
}
